Skip to content

refactor: set controller pattern to navigation#460

Open
tvillega wants to merge 17 commits intoeddyizm:developmentfrom
tvillega:refactor-set-controller-pattern-to-navigation
Open

refactor: set controller pattern to navigation#460
tvillega wants to merge 17 commits intoeddyizm:developmentfrom
tvillega:refactor-set-controller-pattern-to-navigation

Conversation

@tvillega
Copy link
Contributor

MainActivity is heavily populated by two kind of methods: navigation and player sheet. When other fragments try to modify something in them (like settings hiding navigation and the player) they need to instantiate the entire activity.

The app is one activity with a swappable fragment, that means that MainActivity needs to be instantiated everywhere to modify the navigation. Kotlin discourages this practice and, despite Java not complaining, it is starting to bring problems on the navigation (see #450 (comment)) that can only be fixed with unmaintainable patches.

This PR uses the Controller Pattern to extract the navigation logic into its own class. This way MainActivity setups the navigation and the fragment can extract the controller and only the controller instead of bringing the entire activity. The navigation stays in sync throughout the app and we don't mess with the life cycle of the UI.

This PR depends on #450, making it more maintainable.

In order to add a toolbar with a back button in settings I needed to extend from a fragment
so I converted SettingsFragment into a fragment and created SettingsContainerFragment,
the latter is injected as a child of SettingsFragment inside a FrameLayout.

Since SettingsContainerFragment extends from PreferenceFragmentCompat, this allows
to swap it for other and, in the bigger picture, allow an arbitrary organization.
Hide bottom navigation bar on portrait and unlock drawer on portrait
@tvillega tvillega changed the base branch from main to development February 25, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant